<template lang="html">
  <div class="registerModel">
    <el-row>
      <el-col :xs="{span:22,offset:1}" :sm="{span:22,offset:1}" :md="{span:20,offset:2}" :lg="{span:20,offset:2}">


<!-- <el-form>

<el-form-item label="">
      <el-input type="text" placeholder="手机号" name="phone"  v-model="phoneNumber"></el-input>
</el-form-item>
<el-form-item label="">
      <el-input placeholder="验证码"  type="text" v-model="verify"></el-input>
</el-form-item>
<el-form-item label="">
      <el-input placeholder="密码"  type="password" v-model="pwdOne"></el-input>
</el-form-item>
<el-form-item label="">
      <el-input placeholder="确认密码"  type="password" v-model="pwdTwo"></el-input>
</el-form-item>
<el-form-item label="">
      <el-input placeholder="邀请码"  type="text" v-model="inviteNumber"></el-input>
</el-form-item>
<el-form-item label="">
  <el-button @click="registeron">注册</el-button>


</el-form-item>
<el-form-item label="">

</el-form-item>
</el-form> -->
<el-form :model="ruleForm2" :rules="rules2" ref="ruleForm2"  class="demo-ruleForm">
  <el-form-item label="">
  <el-select v-model="value" placeholder="用户选择">
      <el-option v-for="item in options"  :label="item.label" :value="item.value">
      </el-option>
  </el-select>
  </el-form-item>
  <el-form-item label="" prop="age">
    <el-input v-model.number="ruleForm2.age" placeholder="手机号"></el-input>
  </el-form-item>

  <el-form-item label="" prop="verify">

        <el-input   placeholder="验证码"  type="text" v-model.number="ruleForm2.verify">
          <el-button  slot="append" @click="getVerify">{{ textb }}</el-button>
        </el-input>
  </el-form-item>
  <el-form-item label="" prop="pass">
    <el-input type="password" v-model="ruleForm2.pass" auto-complete="off" placeholder="密码"></el-input>
  </el-form-item>
  <el-form-item label="" prop="checkPass">
    <el-input type="password" v-model="ruleForm2.checkPass" auto-complete="off" placeholder="确认密码"></el-input>
  </el-form-item>
  <el-form-item label="" prop="invite">
        <el-input placeholder="邀请码"  type="text" v-model="ruleForm2.invite"></el-input>
  </el-form-item>

  <el-form-item>
    <el-button type="primary" @click="submitForm('ruleForm2')">提交</el-button>
    <el-button @click="resetForm('ruleForm2')">重置</el-button>
  </el-form-item>
</el-form>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
    data() {
        let checkAge = (rule, value, callback) => {
            if (!value) {
                return callback(new Error('请输入手机号码!'));
            }
            setTimeout(() => {
                if (!Number.isInteger(value)) {
                    callback(new Error('请输入手机号码!'));
                } else {
                    if (!/^1\d{10}$/gi.test(value)) {
                        callback(new Error("请输入正确手机号码!"));
                    } else {
                        callback();
                    }
                }
            }, 1000);
        };
        let validatePass = (rule, value, callback) => {
            if (value === '') {
                callback(new Error('请输入密码!'));
            } else if (!/((?=.*\d)(?=.*\D)|(?=.*[a-zA-Z])(?=.*[^a-zA-Z]))^.{8,16}$/gi.test(value)) {
                callback(new Error('必须由8-16个英文字母和数字的字符串组成!'));
            } else {
                if (this.ruleForm2.checkPass !== '') {
                    this.$refs.ruleForm2.validateField('checkPass');
                }
                callback();
            }
        };
        let validatePass2 = (rule, value, callback) => {
            if (value === '') {
                callback(new Error('请再次输入密码!'));
            } else if (value !== this.ruleForm2.pass) {
                callback(new Error('两次输入密码不一致!'));
            } else {
                callback();
            }
        };
        let checkVerify = (rule, value, callback) => {
            if (!value) {
                return callback(new Error('请输入验证码!'));
            }

            if (!Number.isInteger(value)) {
                callback(new Error('请输入正确验证码!'));
            } else {
                callback();
            }

        }
        let checkInvite = (rule, value, callback) => {

            callback();

        }
        return {
            isgetverify: false,
            con: 0,
            textb: '获取验证码',
            ruleForm2: {
                pass: '',
                checkPass: '',
                age: '',
                verify: '', //验证码
                invite: '', //邀请码
            },
            rules2: {
                pass: [{
                    validator: validatePass,
                    trigger: 'blur'
                }],
                checkPass: [{
                    validator: validatePass2,
                    trigger: 'blur'
                }],
                age: [{
                    validator: checkAge,
                    trigger: 'blur'
                }],
                verify: [{
                    validator: checkVerify,
                    trigger: 'blur'
                }],
                invite: [{
                    validator: checkInvite,
                    trigger: 'blur'
                }]
            },
            options: [{
                value: '/home/registerConsumer/basic',
                label: '会员'
            }, {
                value: '/home/registerShop/shopBasic',
                label: '商铺'
            }],
            value: '',

        }
    },
    methods: {
        submitForm(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    alert('提交');
                } else {
                    console.log('错误');
                    return false;
                }
            });
        },
        resetForm(formName) {
            this.$refs[formName].resetFields();
        },
        getVerify() {
            if (this.isgetverify == false) {
                //发送请求
                console.log('发送请求');

                var si = setInterval(() => {
                    this.textb = '已发送(' + this.con + ')s'
                    this.con++
                        if (this.con >= 62) {
                            console.log(this.con);
                            this.textb = '获取验证码'
                            this.con = 0
                            this.isgetverify = false
                            window.clearInterval(si)
                        }
                }, 1000)
                this.isgetverify = true
            } else {
                console.log('不发送请求');
            }









        }
    }
}
</script>

<style lang="css">
</style>
